import pygame.font
class ScoreBoard():
    #显示得分的类
    def __init__(self,ai_settings,screen,stats):
        '''初始化显示得分涉及的属性'''
        self.screen = screen
        self.screen_rect = screen.get_rect()
        self.ai_settings = ai_settings
        self.stats = stats

        # 显示得分信息时使用的字体设置
        self.text_color = (30, 30, 30)
        self.font = pygame.font.SysFont('arial', 40)

        # 准备包含最高得分和当前得分的图像
        self.prep_score()

    def prep_score(self):
        '''将得分转换为一副渲染的图像'''
        #函数round()通常让小数精确到小数点后多少位，其中小数位数是由第二个实参指定的
        #然而，如果将第二个实参指定为负数，round()将圆整到最近的10、100、1000等整数倍
        rounded_scoreB=int(round(self.stats.scoreBule,-1))
        rounded_scoreR=int(round(self.stats.scoreRed,-1))
        #蓝队分数
        score_strB="{:,}0".format(rounded_scoreB)
        score_nameB = "BuleTeam:"
        self.score_imageSB=self.font.render(score_strB,True,self.text_color,self.ai_settings.bg_color)
        self.score_imageNB = self.font.render(score_nameB, True, self.text_color, self.ai_settings.bg_color)
        #红队分数
        score_strR="{:,}0".format(rounded_scoreR)
        score_nameR = "RedTeam:"
        self.score_imageSR = self.font.render(score_strR,True,self.text_color,self.ai_settings.bg_color)
        self.score_imageNR = self.font.render(score_nameR, True, self.text_color, self.ai_settings.bg_color)

        # #将得分放在屏幕右下角
        # self.score_rect=self.score_image.get_rect()
        # self.score_rect.right=self.screen_rect.right-50
        # self.score_rect.bottom=50
        # self.score_rect.left = self.screen_rect.right-250
        # #相距50像素

    def show_score(self):
        '''在屏幕左上显示得分'''
        self.screen.blit(self.score_imageNB,(10,10))
        self.screen.blit(self.score_imageSB,(180,10))

        self.screen.blit(self.score_imageNR,(950,10))
        self.screen.blit(self.score_imageSR,(1110,10))


